package models;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import play.db.ebean.Model;

@Entity
@Table(name = "roles")
public class Role extends Model implements be.objectify.deadbolt.core.models.Role {
	
	private static final long serialVersionUID = 1L;
	
	@Column(name = "id")
	@GeneratedValue(generator = "SEQ_TABLE", strategy = GenerationType.TABLE)
	@Id
	@TableGenerator(name = "SEQ_TABLE")
	private long id;
	
	@Column(name = "name")
	private String name;
	
	@Column(name = "created")
	private Date created;
	
	@Column(name = "last_modified")
	private Date lastModified;
	
	public long getId() {
		return id;
	}
	
	public void setId(long id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Date getCreated() {
		return created;
	}
	
	public void setCreated(Date created) {
		this.created = created;
	}
	
	public Date getLastModified() {
		return lastModified;
	}
	
	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}
	
	public static final Finder<Long, Role> find = new Finder<Long, Role>(long.class, Role.class);
	
	public static Role findByRoleName(final String roleName) {
		return find.where().eq("name", roleName).findUnique();
	}
}
